(function(undefined){
    var album_obj = {};

    /**
     * 上传照片，提交
     * 
     * @author zhouqi 2012-4-17 AM 09:56:02
     * @param {Object} obj    表单对象
     */
    album_obj.up_pic_submit = function(obj) {
        if($('#album_sel').val() < 1) {
            $('#album_sel').focus();
            return false;            
        }

        $(obj).find('input:submit').attr('disabled', 'disabled').blur();
        $.post('/handle.php', $(obj).serializeArray(), function(data){
            data = common_fun_obj.str_to_json(data);

            dialog.finish({
                content: data.msg,
                success: data.state,
                callback: function(){
                    location.href = '/user/album_list';
                }
            });
        });

        return false;        
    }

    /**
     * 弹出相册编辑框
     * @author <zhufu159239@163.com> 2012-04-10 13:08:17
     * @param {Integer} id 如果是编辑模式则传入要编辑的相册id,创建新相册省略
     */
    album_obj.show_edit = function(id){
        id || (id=0);

        frame_data = {
            is_resize: false,
            top: {
                is_show: true,
                btn_max: false,
                btn_min: false,
                height: 30,
                is_move: false
            },
            is_scroll: false,
            min_width: 400,
            min_height: 200,
            is_center: true,
            is_lock_back: true,
            name: 'album_frame'
        }

        if(id > 0){
            //是编辑模式
            frame_data.title = "编辑相册";
            frame_data.content = "/user/album?id=" + id;
        }else{
            //是新建相册
            frame_data.title = "新建相册";
            frame_data.content = "/user/album";
        }

        dialog.iframe(frame_data);

    }
    /**
     * 相册编辑的提交检查
     * @author <zhufu159239@163.com> 2012-04-10 16:04:17
     * @param {Object} obj 表单对象
     */
    album_obj.edit_submit = function(obj){

        if(!$.trim($(obj).find('input:text').val())) {
            $(obj).find('input:text').focus();
            return false;
        }

        $(obj).find('input:submit').attr('disabled', 'disabled').blur();
        $.post('/handle.php', $(obj).serializeArray(), function(data) {
            data = common_fun_obj.str_to_json(data);
            var msg = "操作失败";
            var flag = false;
            if(data.state){
                //操作成功
                msg = "操作成功";
                flag = true;
            }
            //弹出提示信息
            dialog.finish({
                content:msg,
                success:flag,
                callback: function(){
                    parent.location.reload();
                }
            });
        });

        return false;
    }
    /**
     * 弹出删除对话框
     * @author <zhufu159239@163.com> 2012-04-12 15:25:10
     */
    album_obj.album_delete_dislog = function(id, count, album_count){
        frame_data = {
            is_resize: false,
            title: "删除相册",
            content: "/app/album/pic_delete?id="+id,
            top: {
                is_show: true,
                btn_max: false,
                btn_min: false,
                height: 30,
                is_move: false
            },
            is_scroll: false,
            min_width: 400,
            min_height: 200,
            is_center: true,
            is_lock_back: true,
            name: 'album_delete'
        }
        dialog.iframe(frame_data);
    }

    /**
     * 删除一个相册
     * @param {Integer} id 要删除的相册id
     */
    album_obj.album_delete = function(obj){
        obj.submit.disabled = true;
        $(obj).find('input:submit').attr('disabled', 'disabled').blur();
        $.getJSON('/handle.php', $(obj).serializeArray(), function(data){
            $(obj).find('input:submit').attr('disabled', '');
            if(data.state){
                //删除成功
                //弹出提示信息
                dialog.finish({
                    content:data.data,
                    success:true,
                    callback: function(){
                        parent.location.reload()
                    }
                });                
            }else{
                //弹出提示信息
                dialog.finish({
                    content:data.data,
                    success:false,
                    callback: function(){
                        parent.location.reload()
                    }
                });
            }
        })
        return false;
    }
    /**
     * 删除一张照片
     * @author <zhufu159239@163.com> 2012-04-12 17:31:50
     * @param {Object} id
     */
    album_obj.pic_delete = function(id){        
        if(!confirm("确定删除该照片？")){
            return false;
        }

        $.getJSON('/handle.php', {h:"user_album/pic_delete",id:id}, function(data){
            if(data.state){
                //删除成功
                //弹出提示信息
                dialog.finish({
                    content:data.msg,
                    success:true,
                    callback: function(){
                        location.reload()
                    }
                });                
            }else{
                //弹出提示信息
                dialog.finish({
                    content:data.msg,
                    success:false,
                    callback: function(){
                        location.reload()
                    }
                });
            }
        })
        return false;
    }

    /**
     * 设置照片封面图
     * @author <zhufu159239@163.com> 2012-04-11 16:29:39
     */
    album_obj.set_cover = function(id){
        if(!id){
            return false;
        }
        $.getJSON('/handle.php', {h:'user_album/set_cover',id:id}, function(data){
            //弹出提示信息
            dialog.finish({
                content:data.msg,
                success:data.state,
                callback:function(){
                    location.reload()
                }
            });
        })
        return false;
    }

    /**
     * 照片编辑弹出框
     * @author <zhufu159239@163.com> 2012-04-12 16:30:38
     * 
     * @author yufu 2012-08-14 13:44:30
     */
    album_obj.pic_edit_dialog = function(id){
        frame_data = {
            is_resize: false,
            title: "照片编辑",
            content: "/user/pic_edit?id="+id,
            top: {
                is_show: true,
                btn_max: false,
                btn_min: false,
                height: 30,
                is_move: false
            },
            is_scroll: false,
            min_width: 400,
            min_height: 200,
            is_center: true,
            is_lock_back: true,
            name: 'pic_edit'
        }
        dialog.iframe(frame_data);
        return false;
    }

    /**
     * 照片编辑提交检查函数
     * @author <zhufu159239@163.com> 2012-04-12 17:00:08
     * @param {Object} obj
     */
    album_obj.pic_edit_submit = function(obj){
        if(!$.trim($(obj).find('input:text').val())) {
            $(obj).find('input:text').focus();
            return false;            
        }

        $(obj).find('input:submit').attr('disabled', 'disabled').blur();
        $.getJSON('/handle.php', $(obj).serializeArray(), function(data){
            dialog.finish({
                content:data.msg,
                success:data.state,
                callback:function(){
                    parent.location.reload();
                }
            });            
        });

        return false;
    }


    if(window.album_obj == undefined){
        window.album_obj = album_obj;
    }
})();

